function LinearMove() {
    this._keyPoints = null;
    this._kpIndex = 0;
    this._identVec = null;
    this._curPos = new Point2D();
    this._stop = true;
}

LinearMove.prototype.setPos = function( param1, param2) {
    if ( typeof param2 == 'undefined') {
        this._curPos.x = param1.x;
        this._curPos.y = param1.y;
    }
    else {
        this._curPos.x = param1;
        this._curPos.y = param2;
    }
}

LinearMove.prototype._computeVec = function() {
    var targetPos;
    while ( 1) {
        targetPos = this._keyPoints[this._kpIndex];
        if ( Math.abs( this._curPos.x - targetPos.x) > 0.001 || Math.abs( this.curPos.y - targetPos.y) > 0.001)
            break;
        if ( ++this._kpIndex == this._keyPoints.length) {
            this._stop = true;
            break;
        }
    }
    
    this._identVec = targetPos.sub( this._curPos).normalize;
}

LinearMove.prototype.moveTo = function( keyPoints) {
    this._keyPoints = new Array();
    if ( typeof keyPoints.length == 'number' && typeof keyPoints.sort = 'function') {
        for ( var k in keyPoints) {
            var pt = keyPoints[k];
            this._keyPoints.push( new Point2D( pt.x, pt.y));
        }
    }
    else {
        this._keyPoints.push( new Point2D( keyPoints.x, keyPoints.y));
    }
    this._kpIndex = 0;
    this._stop = false;
    this._computeVec();   
}

LinearMove.prototype._realMove = function( d) {
    this._curPos.x += d * this._identVec.x;
    this._curPos.y += d * this._identVec.y;    
}

LinearMove.prototype.update = function( moveV, tickTime) {
    if ( this._stop)
        return this._curPos;
        
    var canMov = movV * tickTime;
    var t0 = this._keyPoints[this._kpIndex];
    var distance = t0.sub( this._curPos).length();
    if ( canMov <= distance) {
        this._realMove( canMov);
        return this._curPos;
    }
    else {
        this._curPos.x = this._keyPoints[this._kpIndex].x;
        this._curPos.y = this._keyPoints[this._kpIndex].y
        
        if ( ++this._kpIndex == this._keyPoints.length)
        	this._stop = true;
       	else
        	this._computeVec();
        if ( this._stop) {
            var lastPos = this._keyPoints[this.keyPoints.length-1];
            this._curPos.x = lastPos.x;
            this._curPos.y = lastPos.y
            return this._curPos;
        }

        var t = tickTime * ( 1 - distance / canMov);
        return this.update( moveV, t);
    }
}
